#!/usr/bin/env python
# -*- coding: utf-8 -*-

from gtk import *
import gobject
from header import *
from browser import *
from photolist import * 
from includes import *
from photoview import *
from photoformat import *

class PhotoPrintManager(Window):
	def __init__(self):
		Window.__init__(self)
		
		self.step = STEP_SELECTION
		self.list = PhotoList()
		
		vertical_box = VBox()
		self.header = Header()
		self.photoformat = PhotoFormat(self)
		self.browser = Browser(self)
		self.photoview = PhotoView(self)
		vertical_box.pack_start(self.header, expand=False)
		
		self.pages = Notebook()
		self.pages.set_show_border(False)
		self.pages.set_show_tabs(False)
		
		
		self.pages.append_page(self.photoview)
		
		self.pages.append_page(self.photoformat)
		self.pages.append_page(Label("Page 3"))
		
		vertical_box.pack_start(HSeparator(), expand=False)
		vertical_box.pack_start(self.pages)
		vertical_box.pack_start(HSeparator(), expand=False)
		
		
		vertical_box.pack_start(self.browser, expand=False, padding=5)
		self.sb = Statusbar()
		self.stop = Button()
		self.stop.connect("clicked", self.stop_loading)
		self.stop.add(image_new_from_stock(STOCK_STOP, icon_size_register("very-little-image", 10, 10)))
		self.stop.set_tooltip_text("Arrêter le chargement")
		self.sb.pack_start(self.stop, expand=False)
		self.progress = ProgressBar()
		self.sb.pack_start(self.progress, expand=False)
		vertical_box.pack_start(self.sb, expand=False)
		
		self.add(vertical_box)
		
		self.set_title("Photo Print Manager")
		self.set_default_size(800, 600)
		self.set_position(WIN_POS_CENTER)
		self.show_all()
		self.progress.hide()
		self.stop.hide()
		self.connect("delete-event", self.quit_application)
		
		
		self.handler = None
		
		self.get_settings().set_long_property("gtk-button-images", 1, "ppm:photoprintmanager")
		
		f="../img/test/00660_splash_2560x1600.jpg"
		self.list.append(Photo([f,gdk.pixbuf_get_file_info(f)]))
		f="../img/test/01324_newyorkcitybypaulobarcellosjr_2560x1600.jpg"
		self.list.append(Photo([f,gdk.pixbuf_get_file_info(f)]))
		f="../img/test/01337_inhisfathersfootsteps_2560x1600.jpg"
		self.list.append(Photo([f,gdk.pixbuf_get_file_info(f)]))
		f="../img/test/01465_frozentree_2560x1600.jpg"
		self.list.append(Photo([f,gdk.pixbuf_get_file_info(f)]))
		
	def quit_application(self, ppm, event):
		if self.handler and self.handler.isAlive():
			self.handler.quit()
		else:
			main_quit()
		return True
		
		
	def stop_loading(self, button):
		self.handler.stop()
		
	def next(self, button):
		if self.step != STEP_CROPPING:
			self.step += 1
			self.header.update_step(self.step)
			self.browser.update_step(self.step)
			self.pages.next_page()
		#else:
		# TODO : print !
		
		
	def previous(self, button):
		self.step -= 1
		self.header.update_step(self.step)
		self.browser.update_step(self.step)
		self.pages.prev_page()
		
	def create_handler(self):
		if not self.handler or not self.handler.isAlive():
			self.handler = ActionHandler(self)
			
	def start_handler(self):
		if not self.handler.isAlive():
			self.handler.start()
	
		
	
if __name__ == '__main__':
	gobject.threads_init()
	gdk.threads_init()
	PhotoPrintManager()
	gdk.threads_enter()
	main()
	gdk.threads_leave()

